<?php
/**
 * Description of LessThan
 *
 * @author      Maciej Zawieja.
 * @link        http://akvus.pl
 * @package     Akvus Framework.
 * @subpackage  Libraries.
 * @copyright   2011 All rights reserved for Maciej Zawieja.
 * @version     1.0.0 - 19.08.2011 (Framework 1.3)
 */
class Between implements iValidation {

    const PARAMS_QUANTITY = 2;

    private $max;

    private $min;

    public function isValid($text) {
        if ( !is_numeric( $this->min ) )
            throw new ValidationException ('Minimum must be a number.', ValidationException::NOT_NUMBER);

        if( !is_numeric( $this->max ) )
            throw new ValidationException ('Maximum must be a n umber.', ValidationException::NOT_NUMBER);

        if( !is_numeric($text) )
            throw new ValidationException ('Value must be a number', ValidationException::NOT_NUMBER);

        if( $this->min > $this->max || $this->max < $this->min )
            throw new ValidationException ('Max can not be greater than min.', ValidationException::PARAMS_DISCREPANT);

        if ( $text < $this->min )
            throw new ValidationException('Numer is too small.', ValidationException::TO_SMALL);

        if( $text > $this->max )
             throw new ValidationException ('Number is too big', ValidationException::TO_BIG);
    }

    public function setParams( array &$params ) {
        if ( count($params) < self::PARAMS_QUANTITY )
                throw new ProgrammerException ('Too less params for RegEx validation.', 0);

        $this->min = $params[0];
        $this->max = $params[1];
    }

    function Max( $max = null )
    {
        if ($max === null) return $this->max;
        $this->max = $max;
        return $this;
    }

    function Min( $min = null )
    {
        if ($min === null) return $this->min;
        $this->min = $min;
        return $this;
    }
}